package listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JButton;

import view.CutGlassPane;
import view.MainFrame;
import controller.LayerController;
import controller.ToolBarController;

public class CutGlassPaneListener implements MouseListener, MouseMotionListener, ActionListener
{

    @Override
    public void actionPerformed(ActionEvent e)
    {
        JButton butSrc = (JButton) e.getSource();
        if (butSrc.getName().equals("confirm")){
            CutGlassPane cutGlassPane = (CutGlassPane)MainFrame.getInstance().getGlassPane();
            LayerController.cutImageTo(cutGlassPane.getTopLeftPoint() ,
                    cutGlassPane.getBottomRightPoint());
            ToolBarController.glassPaneOff();
        }
        if (butSrc.getName().equals("cancel")){
            ToolBarController.glassPaneOff();
        }
    }

    @Override
    public void mouseDragged(MouseEvent e)
    {
        CutGlassPane glassPane = (CutGlassPane)MainFrame.getInstance().getGlassPane();
        glassPane.drawACutRect(e.getX(), e.getY());
    }
    

    @Override
    public void mousePressed(MouseEvent e)
    {
        CutGlassPane glassPane = (CutGlassPane)MainFrame.getInstance().getGlassPane();
        glassPane.setTopLeftCorner(e.getX(), e.getY());
    }
    
    //---- NOT USE ------//

    @Override
    public void mouseMoved(MouseEvent arg0)
    {
    }

    @Override
    public void mouseClicked(MouseEvent arg0)
    {
    }

    @Override
    public void mouseEntered(MouseEvent arg0)
    { 
    }

    @Override
    public void mouseExited(MouseEvent arg0)
    {
    }

    @Override
    public void mouseReleased(MouseEvent arg0)
    {
    }

}
